package com.community.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;


@RestController
@Tag(name = "大模型调用")
@Slf4j
public class ChatController {
    @Autowired
    private ChatClient chatClient;

    @PostMapping("/chat/v1")
    @Operation(summary = "聊天调用")
    public String chat(String msg,String chatId) {//@RequestParam代表参数必传  msg用户输入的提示词
        return chatClient.prompt().user(msg)
                .advisors(a->a.param(ChatMemory.CONVERSATION_ID, chatId))
                .call().content();
    }

    @PostMapping("/chat/v2")
    @Operation(summary = "聊天流式调用")
    public Flux<String> chat2(String msg,String chatId) {//流式调用
        Flux<String> stream = chatClient.prompt().user(msg)
                .advisors(a->a.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream().content();
        return stream;
    }



}